Skip to content

chore: simplify http/response memoization, docs, and exception constructors#187

Merged
OmarAlJarrah merged 1 commit into
mainfrom
chore/175-http-response-cleanups
Jun 28, 2026
Merged

chore: simplify http/response memoization, docs, and exception constructors#187
OmarAlJarrah merged 1 commit into
mainfrom
chore/175-http-response-cleanups

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Three small, self-contained cleanups in the http/response subsystem. None changes runtime behavior — each reuses a stdlib primitive, fixes stale documentation, or removes copy-pasted boilerplate.

1. ParsedResponse — memoize with kotlin.Result

The class hand-rolled a private Outcome sealed class (Success/Failure) purely to memoize the handler's result-or-throw. That is exactly what kotlin.Result models, and the module already uses runCatching/getOrThrow elsewhere. Storing the memo as a nullable Result<T>? keeps the deliberate "null success vs. not-yet-parsed" distinction, and runCatching catches Throwable (not just Exception), so the existing semantics — including memoizing an Error so a later call can't re-read the single-use body — are preserved exactly. Call sites are unchanged.

2. ResponseBody — align the class KDoc with the real contract

The class KDoc described a byteStream/bytes/string API that this type never declared; its only read accessor is source(): BufferedSource. The doc was also the sole reference to java.io.InputStream, so it dragged along an unused import (which ktlint's no-unused-imports rule under allWarningsAsErrors would flag once the doc stopped mentioning it). The KDoc now describes the actual source() contract and the import is removed.

3. HttpException — funnel the 18 subclass constructors through one base constructor

Each of the 18 concrete subclasses repeated the same six-argument block unpacking response.status/response.headers/response.body into the base constructor. Hoisting that into a single protected constructor that takes the Response directly collapses every subclass to a one-line delegation. The subclasses' public (response, message?, cause?, value?) surfaces are byte-for-byte unchanged.

API impact

Adds one protected constructor to HttpException; the regenerated sdk-core.api snapshot is committed. No public signatures change.

Verification

./gradlew :sdk-core:build passes — tests, ktlint, detekt, apiCheck, and the coverage gate.

Closes #175

…uctors

Three self-contained cleanups in the http/response subsystem, none of which
changes runtime behavior:

- ParsedResponse: replace the bespoke private Outcome sealed class with a
  memoized kotlin.Result. runCatching/getOrThrow preserve the exact
  Throwable-catching and memoize-before-throw semantics, and a nullable
  Result<T>? keeps the deliberate null-success vs. unparsed distinction.

- ResponseBody: rewrite the class KDoc around the real source(): BufferedSource
  contract (it previously described byteStream/bytes/string methods the type
  never declared) and drop the now-unused java.io.InputStream import.

- HttpException: add one protected constructor that unpacks status/headers/body
  from a Response, and collapse the 18 subclasses' identical six-argument
  delegation blocks to a single-line delegation. Subclass public constructor
  surfaces are unchanged; the new protected constructor is reflected in the
  committed API snapshot.
@OmarAlJarrah OmarAlJarrah merged commit d99e05f into main Jun 28, 2026
1 check passed
@OmarAlJarrah OmarAlJarrah deleted the chore/175-http-response-cleanups branch June 28, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http/response: memoize with kotlin.Result, fix ResponseBody KDoc, dedupe HttpException constructors

1 participant